/**
 * 郭楠project
 * com.gn.controller
 * ArticleController.java
 * 创建人:TonyGuo 
 * 时间：2016年12月1日-下午11:52:01 
 * 2016Tm公司-版权所有
 */
package com.gn.controller;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.gn.commons.BaseMongo;
import com.gn.entity.Article;
import com.gn.entity.Collect;
import com.gn.service.AdminUserService;
import com.gn.service.ArticleService;
import com.gn.service.CollectionService;
import com.gn.util.CommonUtils;

/**
 * 
 * ArticleController
 * 创建人:TonyGuo
 * 时间：2016年12月1日-下午11:52:01 
 * @version 1.0.0
 * 
 */
@RestController
@RequestMapping("/rest")
public class CollectionController {
	@Resource
	CollectionService collectionService;
	
	@Resource
	AdminUserService adminUserService;
	
	/**
	 * 【添加收藏】
	 * @param collect
	 */
	@RequestMapping("collect.add")
	public String saveCollect(Collect collect){
		collectionService.addUserCollect(collect);
		return "true";
	}
	
	/**
	 * 【取消收藏】
	 * @param collect
	 */
	@RequestMapping("collect.delete/{id}")
	public String cancelCollect(@PathVariable("id") String id){
		System.out.println("=====id==="+collectionService.findUserCollectById(id));
		if(collectionService.findUserCollectById(id)!=null){
			collectionService.deleteUserCollect(id);
			return "true";
		}else{
			return "false";
		}
	}
	
	/**
	 * 【取消收藏-更改状态(status:fav/deleted)】
	 * @param id
	 */
	@RequestMapping("collect.cancel/{id}")
	public String updateCollectStatus(@PathVariable("id") String id){
		if(collectionService.findUserCollectById(id)!=null){
			collectionService.updateCollectStatus(id,Collect.STATUS_DELETED);
			return "true";
		}else{
			return "false";
		}
	}
	
	/**
	 * 【用户收藏列表-fav已收藏的】
	 * @param uid
	 */
	@RequestMapping("collect.list.find/{uid}")
	public List<Collect> collectList(@PathVariable("uid") String uid){
		if(adminUserService.findUserByUid(uid)!=null)
			return collectionService.findUserCollectList(uid,Collect.STATUS_FAV);
		else
			return null;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
